﻿<?php
class Content extends CI_Controller{
	function __construct(){
		parent::__construct();
		$this->load->model('M_pages');
		$this->load->helper('url');
		$this->load->library('pagination');
		$this->load->database();
	}
	function index(){
		if(isset($_POST['page'])){
			$page = $_POST['page'];
		}else if(isset($_GET['page'])){
			$page = $_GET['page'];
		}else{
			$page = 1;
		}
		if($page){
			$page_size = 2700;                                                       //每页显示的内容数量
			$base_url = base_url();                                                  //文件的所在路径
			$counter = file_get_contents($base_url."/file.txt");                     //读取指定文件中的内容
			$length = strlen($this->M_pages->unhtml($counter));                      //获取字符串的长度
			$page_count = ceil($length/$page_size);                                  //统计每页的字符数
			$c = $this->M_pages->msubstr($counter,0,($page-1)*$page_size);           //计算上一页
			$c1 = $this->M_pages->msubstr($counter,0,$page*$page_size);              //计算当前页
		    $data['content'] = substr($c1,strlen($c),strlen($c1)-strlen($c));        //输出当前页的内容
			$data['page_count'] = $page_count;
			$data['page'] = $page;
			$this->load->view('header');
			$this->load->view('textbody',$data);
			$this->load->view('footer');
		}
	}
	function showajax(){
		$this->load->view('header');
		$this->load->view('ajaxbody');
	}
	
	function showupdown(){
		$this->load->view('header');
		$this->load->view('updown');
	}
	
	function showstad(){
		$perPage = 5;
		$config['base_url'] = site_url('content/showstad');
		$config['total_rows'] = $this->db->count_all('items');
		$config['per_page'] = $perPage;
		$config['uri_segment'] = 3;
		$config['first_link'] = '首页';
		$config['prev_link'] = '上一页';
		$config['next_link'] = '下一页';
		$config['last_link'] = '尾页';
		$config['first_tag_open'] = '<span aria-hidden="true">';
		$config['first_tag_close'] = '</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		$config['prev_tag_open'] = '<span>';
		$config['prev_tag_close'] = '</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		$config['num_tag_open'] = '<span>';
		$config['num_tag_close'] = '</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		$config['cur_tag_open'] = '<b>';
		$config['cur_tag_close'] = '</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		$config['next_tag_open'] = '<span>';
		$config['next_tag_close'] = '</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		$config['last_tag_open'] = '<span>';
		$config['last_tag_close'] = '</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
		$config['use_page_numbers'] = TRUE;
		$this->pagination->initialize($config);
		$data['links'] = $this->pagination->create_links();
		$pagenum = $this->uri->segment(3);
		if($pagenum == 0){
			$pagenum = 1;
		}
		$offset = ($pagenum-1)*$perPage;
		$query = $this->db->get("items",$perPage,$offset);
		$res = $query->result_array();
		$data['pages'] = ceil($this->db->count_all('items')/$perPage);
		$data['perpage'] = $perPage;
		$data['items'] = $this->db->count_all('items');
		$data['res'] = $res;
		$data['goods'] = $this->db->select('items'); 
		$this->load->view('header');
		$this->load->view('stadbody',$data);
	}
	
	function getajax(){
		$page = $_POST['page'];
		if($page){
			$page_size = 1500;                                                       //每页显示的内容数量
			$base_url = base_url();                                                  //文件的所在路径
			$counter = file_get_contents($base_url."/file.txt");                     //读取指定文件中的内容
			$length = strlen($this->M_pages->unhtml($counter));                      //获取字符串的长度
			$page_count = ceil($length/$page_size);                                  //统计每页的字符数
			$c = $this->M_pages->msubstr($counter,0,($page-1)*$page_size);           //计算上一页
			$c1 = $this->M_pages->msubstr($counter,0,$page*$page_size);              //计算当前页
		    $content = substr($c1,strlen($c),strlen($c1)-strlen($c));				 //输出当前页的内容
		}
		echo $content;
	}
	
}
?>